home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1995 / MacHack 1995.toast / Presentations / Presentations ’90 / A⁄Rose Techniques / FunMacros.h next >
Text File  |  1990-06-08  |  2KB  |  61 lines

  1. /*
  2.  *    FunMacros.h - Fun macros to use in A/ROSE development.
  3.  *
  4.  *    Mark D. Rustad.    6/8/90.
  5.  */
  6.  
  7.  
  8. /*    Functions */
  9.  
  10. /*
  11.  *    The following three macros allow the mSData, mOData and mDataPtr to
  12.  *    be accessed as if they were other types.  For instance:
  13.  *
  14.  *        xxx(AROSEmessage *mp)
  15.  *        {
  16.  *            struct abc
  17.  *            {
  18.  *                short    s1;
  19.  *                char    c1[2];
  20.  *            };
  21.  *
  22.  *            printf("3rd byte of mOData is %02X\n", ODataAs(unsigned char, mp)[2]);
  23.  *            printf("c1[1] in mSData is %02X\n", SDataAs(struct abc, mp)->c1[1]);
  24.  *        }
  25.  */
  26.  
  27. #define    ODataAs(x,y)    ((x *)((y)->mOData))
  28. #define    SDataAs(x,y)    ((x *)((y)->mSData))
  29. #define    DPAs(x,y)    ((x *)((y)->mDataPtr))
  30.  
  31.  
  32. /*
  33.  *    The following macro will swap the mFrom and mTo addresses, set to low-order
  34.  *    bit of mCode (to indicate a reply), set mStatus to the indicated value and
  35.  *    send the message.  This could actually all be done as an MPW 3.0 C in-line
  36.  *    function.  Anyone game to try it?
  37.  */
  38.  
  39. #define    Reply(x,y)    {tid_type t;\
  40.                         t = (x)->mFrom, (x)->mFrom = (x)->mTo, (x)->mTo = t;\
  41.                         (x)->mCode |= 1;\
  42.                         (x)->mStatus = y;\
  43.                         Send(x);\
  44.                     }
  45.  
  46.  
  47.  
  48. /*
  49.  *    The following macro will calculate the offset (in bytes) to the field
  50.  *    given in the second argument within the structure given in the first
  51.  *    argument.  This evaluates to a constant at compile time.  For example:
  52.  *        GetOffset(AROSEmessage, mFrom)
  53.  *    evaluates to 14.  Among other things, this allows symbolic references to
  54.  *    fields in structures in MPW in-line expansions.
  55.  */
  56.  
  57. #define    GetOffset(x,y) (&((x *)0)->y)
  58.  
  59.  
  60. /*    End of FunMacros.h    */
  61.